package com.apes.hr.transfer.comprehensive;

import com.alibaba.fastjson.JSONObject;
import com.apes.framework.query.ApesDao;
import com.apes.framework.query.SqlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @Title: ComprehensiveDao
 * @Description:
 * @author: ZhengZeXian
 * @create: 2021/2/19 14:18
 */
@Component
public class ComprehensiveDao extends ApesDao {

    @Autowired
    private SqlService sqlService;

    /**
     * 获取行政部门ID
     * @return
     */
    public String queryBranchId(String postID){
        JSONObject param = new JSONObject();
        param.put("POST_ID",postID);
        String sql = "SELECT D.BRANCH_ID FROM MAS_DEPT D WHERE D.ID = (SELECT L.ORG_ID FROM AUT_LOCAL_PERMIT_ITEM L " +
                "WHERE L.LOCAL_PERMIT_ID = (SELECT P.LOCAL_PERMIT_ID FROM AUT_POSTS P WHERE P.ID = :POST_ID) AND L.PURPOSE = 'pp_search' AND L.TYPE = 'pt_dept')";
        List<Map> maps = this.find(sql, param);
        if(maps.isEmpty()){
            return "";
        }
        return this.find(sql, param).get(0).get("BRANCH_ID").toString();
    }
}
